package version2024.easy;

import java.util.Scanner;
import java.util.TreeMap;

/**
 * @author sunhl
 * @Description: HJ8 合并表记录
 * @Date: created in 2025/1/11 星期六 15:45
 * @Modified By:
 */
public class HJ8_MergedTableRecord {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            // 输出结果要求有序
            TreeMap<Integer, Integer> map = new TreeMap<>();

            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                int k = in.nextInt();
                int v = in.nextInt();
                map.put(k, map.getOrDefault(k, 0) + v);
            }

            for (Integer i : map.keySet()) {
                System.out.println(i + " " + map.get(i));
            }
        }
    }
}
